package com.xxx.dorm.service.impl;

import com.xxx.dorm.dao.UserDao;
import com.xxx.dorm.dao.impl.UserDaoImpl;
import com.xxx.dorm.domain.Role;
import com.xxx.dorm.domain.Users;
import com.xxx.dorm.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();

    @Override
    public Users logins(Users users) {
        Users u = userDao.findByusernameAndPassword(users.getUsername(),users.getPassword());
        return u;

    }

    @Override
    public void updatePassword(Integer id, String password) {
        userDao.updatePassword(id,password);
    }

    /**
     * 根据rid获取角色表
     * @param rid
     * @return
     */
    @Override
    public Role findByRid(Integer rid) {
        return userDao.findByRid(rid);
    }

    /**
     * 查找所有用户信息
     * @param userid
     * @return
     */
    @Override
    public List<Users> findAll(Integer userid) {
        return userDao.findAll(userid);
    }

    /**
     * 删除用户
     * @param id
     */
    @Override
    public void removeUser(String id) {
        userDao.removeUser(id);
    }

    @Override
    public Users findById(String id) {
        return userDao.findByid(id);
    }

    @Override
    public void updateUser(Users users) {
        userDao.updateUser(users);
    }

    /**
     * 通过条件查找用户信息
     * @param conditions
     * @param information
     * @return
     */
    @Override
    public List<Users> find(String conditions, String information) {
        return userDao.find(conditions,information);
    }

    @Override
    public void addUser(Users users) {
        userDao.addUser(users);
    }

    @Override
    public Users findOldPassword(String oldPassword) {
        return userDao.findOldPassword(oldPassword);
    }
}
